home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / gfx / jpegaga2.lha / jpegAGAsrc / ppm2aga / ppm.h < prev    next >
C/C++ Source or Header  |  1993-12-24  |  3KB  |  92 lines

  1. /* ppm.h - header file for libppm portable pixmap library
  2. */
  3.  
  4. #ifndef _PPM_H_
  5. #define _PPM_H_
  6.  
  7. #include "pgm.h"
  8.  
  9. typedef gray pixval;
  10.  
  11. #ifdef PPM_PACKCOLORS
  12.  
  13. #define PPM_MAXMAXVAL 1023
  14. typedef unsigned long pixel;
  15. #define PPM_GETR(p) (((p) & 0x3ff00000) >> 20)
  16. #define PPM_GETG(p) (((p) & 0xffc00) >> 10)
  17. #define PPM_GETB(p) ((p) & 0x3ff)
  18. #define PPM_ASSIGN(p,red,grn,blu) (p) = ((pixel) (red) << 20) | ((pixel) (grn) << 10) | (pixel) (blu)
  19. #define PPM_EQUAL(p,q) ((p) == (q))
  20.  
  21. #else /*PPM_PACKCOLORS*/
  22.  
  23. #define PPM_MAXMAXVAL PGM_MAXMAXVAL
  24. typedef struct
  25.     {
  26.     pixval r, g, b;
  27.     } pixel;
  28. #define PPM_GETR(p) ((p).r)
  29. #define PPM_GETG(p) ((p).g)
  30. #define PPM_GETB(p) ((p).b)
  31. #define PPM_ASSIGN(p,red,grn,blu) do { (p).r = (red); (p).g = (grn); (p).b = (blu); } while ( 0 )
  32. #define PPM_EQUAL(p,q) ( (p).r == (q).r && (p).g == (q).g && (p).b == (q).b )
  33.  
  34. #endif /*PPM_PACKCOLORS*/
  35.  
  36.  
  37. /* Magic constants. */
  38.  
  39. #define PPM_MAGIC1 'P'
  40. #define PPM_MAGIC2 '3'
  41. #define RPPM_MAGIC2 '6'
  42. #define PPM_FORMAT (PPM_MAGIC1 * 256 + PPM_MAGIC2)
  43. #define RPPM_FORMAT (PPM_MAGIC1 * 256 + RPPM_MAGIC2)
  44. #define PPM_TYPE PPM_FORMAT
  45.  
  46.  
  47. /* Macro for turning a format number into a type number. */
  48.  
  49. #define PPM_FORMAT_TYPE(f) ((f) == PPM_FORMAT || (f) == RPPM_FORMAT ? PPM_TYPE : PGM_FORMAT_TYPE(f))
  50.  
  51.  
  52. /* Declarations of routines. */
  53.  
  54. void ppm_init ARGS(( int* argcP, char* argv[] ));
  55.  
  56. #define ppm_allocarray( cols, rows ) ((pixel**) pm_allocarray( cols, rows, sizeof(pixel) ))
  57. #define ppm_allocrow( cols ) ((pixel*) pm_allocrow( cols, sizeof(pixel) ))
  58. #define ppm_freearray( pixels, rows ) pm_freearray( (char**) pixels, rows )
  59. #define ppm_freerow( pixelrow ) pm_freerow( (char*) pixelrow )
  60.  
  61. pixel** ppm_readppm( FILE* file, int* colsP, int* rowsP, pixval* maxvalP);
  62. void ppm_readppminit( FILE* file, int* colsP, int* rowsP, pixval* maxvalP, int* formatP);
  63. void ppm_readppmrow( FILE* file, pixel* pixelrow, int cols, pixval maxval, int format );
  64.  
  65. void ppm_writeppm( FILE* file, pixel** pixels, int cols, int rows, pixval maxval, int forceplain );
  66. void ppm_writeppminit ( FILE* file, int cols, int rows, pixval maxval, int forceplain );
  67. void ppm_writeppmrow ( FILE* file, pixel* pixelrow, int cols, pixval maxval, int forceplain );
  68.  
  69. pixel ppm_parsecolor( char* colorname, pixval maxval );
  70. char* ppm_colorname( pixel* colorP, pixval maxval, int hexok );
  71.  
  72. extern pixval ppm_pbmmaxval;
  73. /* This is the maxval used when a PPM program reads a PBM file.  Normally
  74. ** it is 1; however, for some programs, a larger value gives better results
  75. */
  76.  
  77.  
  78. /* Color scaling macro -- to make writing ppmtowhatever easier. */
  79.  
  80. #define PPM_DEPTH(newp,p,oldmaxval,newmaxval) \
  81.     PPM_ASSIGN( (newp), \
  82.     ( (int) PPM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
  83.     ( (int) PPM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
  84.     ( (int) PPM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) )
  85.  
  86.  
  87. /* Luminance macro. */
  88.  
  89. #define PPM_LUMIN(p) ( 0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p) )
  90.  
  91. #endif /*_PPM_H_*/
  92.